home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / r / real_3d / real3dv3.3b.dms / real3dv3.3b.adf / RPL.LZH / RPL / methods.rpl < prev    next >
Text File  |  1995-05-04  |  4KB  |  142 lines

  1. ( ------------------------------------------------------------
  2. ( This example demonstrates how to expand the animation system
  3. ( of Real 3D by defining new methods. The file defines three new
  4. ( methods: ABS_PATH, CHAIN and WEIRD_FORCE. If you add the line
  5. ( "methods.rpl" LOAD to you rpl-startup, these methods will be
  6. ( automatically installed.
  7. ( ------------------------------------------------------------
  8.  
  9. "r3d3:rpl/sys/vectors.rpl" LOAD
  10. "r3d3:rpl/sys/objects.rpl" LOAD
  11. "r3d3:rpl/sys/tags.rpl"    LOAD
  12.  
  13. ( This function is used by all custom methods found from this file.
  14. ( It fetches addresses of all valid target objects on the stack.
  15.  
  16. : GetTargets
  17.     0               ( 0 terminates the list
  18.     o2 FETCH O_GETSUB   ( first sub object
  19.     BEGIN
  20.         DUP IF      ( test if the object address is not zero
  21.             DUP O.wMETHOD + WFETCH ( fetch the contents of wMETHOD field
  22.             NOT IF  ( if zero, valid target
  23.         DUP
  24.             ENDIF
  25.         ELSE        ( object address was zero,
  26.             DROP
  27.             EXIT
  28.         ENDIF
  29.         O_GETNEXT   ( fetch the address of the next object
  30.     AGAIN
  31. ;
  32.  
  33. ( ABS_PATH
  34. ( This is the actual object procedure for ABS_PATH
  35.  
  36. : OP_AbsPath
  37.     GetTargets      ( fetch target objects
  38.     o1 FETCH O_GETSUB   ( find the parameter object
  39.     DUP NOT IF      ( if no parameter object, syntax error
  40.         "Parameter Object Missing" ERROR
  41.     ENDIF
  42.     t FFETCH u FFETCH v FFETCH O_EVAL
  43.     0 M_MOVECOG
  44.     1               ( return 1, everything is okay
  45. ;
  46.  
  47. ( This creates the method ABS_PATH
  48.  
  49. & OP_AbsPath "ABS_PATH" MTH_CREATE DROP
  50.  
  51. ( The CHAIN method attemps to keep the distance between all objects
  52. ( the same.
  53.  
  54. FVARIABLE fLen
  55. VVARIABLE vTmp
  56.  
  57. : Distribute ( 0 aObjects .... fDist )
  58.     fLen FSTORE
  59.     iOP_COG O_PROP vTmp VSTORE
  60.     BEGIN
  61.         DUP
  62.     WHILE
  63.         DUP iOP_COG O_PROP
  64.         vTmp VFETCH VSUB VNORM
  65.         fLen FFETCH VMUL
  66.         vTmp VFETCH VADD vTmp VSTORE
  67.         0 SWAP vTmp VFETCH 0 M_MOVECOG
  68.     REPEAT
  69.     DROP
  70. ;
  71.  
  72. ( Actual CHAIN Object Procedure. The tag "FDIS" can be associated with
  73. ( the method object in order to define the distance between targets.
  74. ( If the tag is not defined, the default distance 0.5 is used.
  75.  
  76. : OP_Chain
  77.     GetTargets
  78.     o1 FETCH "FDIS" O_FINDTAG DUP
  79.     IF
  80.         4 + FETCH FFETCH
  81.     ELSE
  82.         DROP
  83.         0.5
  84.     ENDIF
  85.     Distribute
  86.     1
  87. ;
  88.  
  89. ( Create CHAIN method
  90.  
  91. & OP_Chain "CHAIN" MTH_CREATE DROP
  92.  
  93. ( The WEIRD_FORCE demonstrates how to create physical oriented `particle-
  94. ( system` methods. The method generates random force fields affecting to
  95. ( the velocity and the spin of target objects.
  96.  
  97. : GetVelForce
  98.     RANDOM 0.5 F- RANDOM 0.5 F- RANDOM 0.5 F- 
  99. ;
  100.  
  101. : GetSpinForce
  102.     RANDOM 0.5 F- RANDOM 0.5 F- RANDOM 0.5 F- 
  103. ;
  104.  
  105. : DoWeirdSPI ( aObj )
  106.     "VSPI" O_FINDTAG DUP        ( attemp to find VSPI tag of given object
  107.     IF                          ( found, so
  108.         T.aVAL + FETCH DUP VFETCH   ( fetch the tag value
  109.         GetSpinForce            ( fetch force affecting to target
  110.         dt FFETCH 6.28 F* VMUL VADD ( calculate new velocity
  111.         4 ROLL VSTORE           ( assign it back to the target`s tag
  112.     ELSE                    ( not found, so create it
  113.         DROP DUP "CEND" 0 0 0 "VSPI" O_CREATAG DROP
  114.     ENDIF
  115. ;
  116.  
  117. : DoWeirdVEL ( aObj )
  118.     "VVEL" O_FINDTAG DUP
  119.     IF
  120.         T.aVAL + FETCH DUP VFETCH GetVelForce dt FFETCH VMUL VADD 4 ROLL VSTORE
  121.     ELSE
  122.         DROP DUP "CEND" 0 0 0 "VVEL" O_CREATAG DROP
  123.     ENDIF
  124. ;
  125.  
  126. : OP_WeirdForce
  127.     GetTargets          ( fetch all targets on the stack
  128.     BEGIN               ( loop through all of them
  129.         DUP
  130.     WHILE
  131.         DUP DoWeirdVEL  ( apply force field to velocity
  132.         DUP DoWeirdSPI  ( apply force field to spin
  133.         DROP
  134.     REPEAT
  135.     DROP
  136.     1                   ( all OK
  137. ;
  138.  
  139. ( Install WEIRD_FORCE method
  140.  
  141. & OP_WeirdForce "WEIRD FORCE" MTH_CREATE DROP
  142.